<?php
namespace Common\Model;

/**
 * 钟点房
 * @modify zhangzhen 2017-5-15 创建
 * @index 无
 */

Class HourRoomModel extends \Common\Model\BaseModel
{
    protected $trueTableName = 'tb_hour_room';

    /**
     * 获取钟点房数据
     * @modify zhangzhen 2017-5-15 创建
     * @param  integer   $id 设施id
     * @return array
     */
    public function getInfosByHotel($hotel) {
        $option = array(
            'hotelentity_id' => $hotel,
            'isdelete' => 0,
        );

        if (is_array($hotel)) {
            $option['hotelentity_id'] = array('in', $hotel);
        }

        $data = $this->where($option)->field('hotelentity_id,roominfo_id,roomtype_id')->select();
        return $data;
    }

    /**
     * 获取钟点房数据
     * @modify zhangzhen 2017-5-15 创建
     * @param  integer   $id 设施id
     * @return array
     */
    public function getInfosByRoomType($roomTypeId) {
        if (is_array($roomTypeId)) {
            $option['roomtype_id'] = ['in', implode(',', $roomTypeId)];
        } else {
            $option['roomtype_id'] = $roomTypeId;
        }
        $data = $this->where($option)->field('hotelentity_id,roominfo_id,roomtype_id')->select();
        return $data;
    }

    /**
     * 获取钟点房数据
     * @modify zhangzhen 2017-5-15 创建
     * @param  integer   $id 设施id
     * @return array
     */
    public function getInfosJoinName($hotel) {
        $data = $this
            ->alias('hour')
            ->join('tb_room_info ON tb_room_info.id = hour.roominfo_id')
            ->join('tb_room_type ON tb_room_type.id = hour.roomtype_id')
            ->where(['hour.hotelentity_id' => $hotel, 'hour.isdelete' => 0])
            ->field('roominfo_id,hour.roomtype_id,tb_room_info.name as roomname,tb_room_type.name as typename')
            ->select();
        return $data;
    }
    /**
     * 批量添加钟点房
     * @modify zhangzhen 2017-5-15 创建
     * @param  array   $dataList = [
                            'hotel',
                            'price',
                            'roomInfoIds',
                            'roomTypeId',
                        ];
     * @return boolean 执行结果
     */
    public function addAllInfos(array $dataList) {
        $result = $this->addAll($dataList);
        return $result;
    }

    /**
     * 根据房间软删除钟点房
     * @modify zhangzhen 2017-5-15 创建
     * @param  string   $waitForDelete implode(',')
     * @return boolean 执行结果
     */
    public function deleteInfosInIds($waitForDelete) {
        if (is_array($waitForDelete)) {
            $waitForDelete = implode(',', $waitForDelete);
        }
        $option['roominfo_id'] = ['in', $waitForDelete];
        $data['isdelete'] = IS_DELETE;
        $result = $this->where($option)->save($data);
        return $result === false ? false : true;
    }

    /**
     * 根据房型软删除钟点房
     * @modify zhangzhen 2017-5-16 创建
     * @param  string   $waitForDelete implode(',')
     * @return boolean 执行结果
     */
    public function deleteInfoByTypeId($roomTypeId) {
        $option['roomtype_id'] = $roomTypeId;
        $data['isdelete'] = IS_DELETE;
        $result = $this->where($option)->save($data);
        return $result === false ? false : true;
    }
}
